#include "msp430g2553.h"

void startUart();

void stopUart();

void eraseFlash(char *address);

void writeFlash(char *address,char values[],int length);

 

void main(void){

WDTCTL = WDTPW + WDTHOLD;	 // Stop WDT

BCSCTL1 = CALBC1_1MHZ;	 // Set range

DCOCTL = CALDCO_1MHZ;	  

BCSCTL2=SELM_0+DIVM_0;

FCTL2=FWKEY+FSSEL_1+FN2;

//program=(volatile char *)0x1000; //Address for program start

P1IES=BIT3;

P1IE=BIT3;

P1IFG=0;

P1DIR=BIT0+BIT6;

P1OUT=0;

startUart();

for(;;){

__bis_SR_register(LPM0_bits+GIE);

}

}

void startUart(){

UCA0CTL1=UCSWRST;

UCA0CTL0=0;

UCA0CTL1|=UCSSEL_2;

UCA0BR0 = 104;                            // 1MHz 9600

UCA0BR1 = 0;                              // 1MHz 9600

UCA0MCTL = UCBRS0;

UCA0CTL1&=~UCSWRST;
IE2=UCA0RXIE;
P1SEL=BIT1+BIT2;

P1SEL2=BIT1+BIT2;

}

void stopUart(){

UCA0CTL1=UCSWRST;

}

void eraseFlash(char *address){

__bic_SR_register(GIE);

FCTL1=FWKEY+ERASE;

FCTL3=FWKEY;

*address=0;

FCTL1=FWKEY;

FCTL3=FWKEY+LOCK;

}

 

void writeFlash(char *address,char values[],int length)
{
int j;
FCTL3=FWKEY;
FCTL1=FWKEY+WRT;


for(j=0;j<length;j++){

*address=values[j];

address++;

}

FCTL1=FWKEY;

FCTL3=FWKEY+LOCK;

}

#pragma vector=USCIAB0RX_VECTOR

__interrupt void RX_ISR(){

P1OUT^=BIT0;

switch(UCA0RXBUF){

case 'a':

P1OUT^=BIT0;

break;

case 'b':

P1OUT^=BIT6;

break;

case 'c':

UCA0TXBUF='m';

break;

}

}
/*

		if(rxBuffer=='A') 
		{		  
		P1OUT &= ~BIT3;
		P1OUT &= ~BIT4;
		P1OUT &= ~BIT5;
		P1OUT &= ~BIT7;
		}  
		else if(rxBuffer =='B')
		{	  
		P1OUT &= ~BIT3;
		P1OUT &= ~BIT4;
		P1OUT |= BIT5;
		P1OUT |= BIT7;
		} 
		else if(rxBuffer =='C')
		{	  
		P1OUT &= ~BIT3;
		P1OUT &= ~BIT4;
		P1OUT &= ~BIT5;
		P1OUT |= BIT7;
		} 
		else if(rxBuffer =='D')
		{	  
		P1OUT &= ~BIT3;
		P1OUT &= ~BIT4;
		P1OUT |= BIT5;
		P1OUT &= ~BIT7;
		} 
        __delay_cycles(5000);
        __delay_cycles(5000);      
        __delay_cycles(5000);
        __delay_cycles(5000);
        __delay_cycles(5000);
        __delay_cycles(5000);      
        __delay_cycles(5000);
        __delay_cycles(5000);
        __delay_cycles(5000);
        __delay_cycles(5000);      
        __delay_cycles(5000);
        __delay_cycles(5000);
        		P1OUT &= ~BIT0;		  
    }

}
*/
